﻿using System;
using System.Runtime.Serialization;
using System.Windows.Media.Imaging;
using EshubaAnalyser;

namespace Common
{
    [Serializable]
    public abstract class EshubaLink : HyperLink, ISerializable
    {
        public EshubaLink() { }

        protected EshubaLink(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            this.Guid = info.TryGetValue<Guid>("Guid");
            this.ParentGuid = info.TryGetValue<Guid>("ParentGuid");
            this.Remark = info.TryGetValue<string>("Remark");
        }

        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);
            info.AddValue("Guid", Guid);
            info.AddValue("ParentGuid", ParentGuid);
            info.AddValue("Remark", Remark);
        }

        public Guid Guid { get; set; }

        public Guid ParentGuid { get; set; }

        public BitmapImage Icon { get { return null; } }

        public string Remark { get; set; }

        public abstract string GetRelativePath();

        protected string GetParentRelativePath(EshubaMenu menu)
        {
            if (menu == null) return string.Empty;
            EshubaMenu parentMenu = EshubaCache.Instance.MenuCache.TryGetValue(menu.ParentGuid);
            if (parentMenu == null) return string.Empty + "\\" + menu.Text;
            return parentMenu.GetRelativePath() + "\\" + menu.Text;
        }
    }
}
